package com.cms.recursoshumanos.component.base;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.CheckboxField;

public class CustomCheckboxFieldColored extends CheckboxField {
	int highlightColor;
	static final Bitmap check = Bitmap.getBitmapResource("img/checked_checkbox.png");
	static final Bitmap uncheck = Bitmap.getBitmapResource("img/unchecked_checkbox.png");
	
	public CustomCheckboxFieldColored( String text, boolean checked, int highlightColour)
	{
		super(text, checked);
		setPadding(2, 2, 2, 2);
		this.highlightColor = highlightColour;
	}
	
	protected void layout(int width, int height) {
		super.layout(width, height);
		setExtent(check.getWidth()+20+getFont().getAdvance(getLabel()), getHeight());
	}
	protected void paint(Graphics graphics) {
		if(isFocus()) {
			XYRect contentRect = new XYRect();
			getFocusRect(contentRect);
			graphics.setColor(highlightColor);
			graphics.fillRect(contentRect.x, contentRect.y, contentRect.width, contentRect.height);
			graphics.setColor(Color.WHITE);
		}
		int xText, y;
		if(getChecked()) {
			xText = check.getWidth();
			y = (getContentHeight()-check.getHeight())/2;
			graphics.drawBitmap(5, y, check.getWidth(), check.getHeight(), check, 0, 0);
		} else {
			xText = uncheck.getWidth();
			y = (getContentHeight()-uncheck.getHeight())/2;
			graphics.drawBitmap(5, y, uncheck.getWidth(), uncheck.getHeight(), uncheck, 0, 0);
		}
		
		y = (getContentHeight()-getFont().getHeight())/2;
		graphics.drawText(getLabel(), xText+15, y);
	}
	
	protected void drawFocus(Graphics graphics, boolean on) {}
	protected void paintBackground(Graphics arg0) {	}
}
